package de.klenkse.eclipse.ftpsync.editor;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.part.FileEditorInput;

import de.klenkse.eclipse.ftpsync.ErrorManager;
import de.klenkse.eclipse.ftpsync.FTPSyncSetupException;
import de.klenkse.eclipse.ftpsync.model.FTPConfigModel;
import de.klenkse.eclipse.ftpsync.model.FTPSyncModelUtils;

/**
 * The editor for synchronization configuration.
 */
public class FTPSyncConfigEditor extends EditorPart {

	/**
	 * The model.
	 */
	private FTPConfigModel model;

	/**
	 * The input file.
	 */
	private IFile inputFile;

	/** {@inheritDoc} */
	@Override
	public void doSave(IProgressMonitor monitor) {
		FTPSyncModelUtils.saveModel(model, inputFile);
	}

	/** {@inheritDoc} */
	@Override
	public void doSaveAs() {
		// not supported.
	}

	/** {@inheritDoc} */
	@Override
	public void init(IEditorSite site, IEditorInput input) {
		setInput(input);
		setSite(site);
		if (input instanceof FileEditorInput) {
			inputFile = ((FileEditorInput) input).getFile();
			try {
				model = FTPSyncModelUtils.openModel(inputFile);
			} catch (FTPSyncSetupException e) {
				ErrorManager.addError(e, inputFile);
			}
		}
	}

	/** {@inheritDoc} */
	@Override
	public boolean isDirty() {
		return false;
	}

	/** {@inheritDoc} */
	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

	/** {@inheritDoc} */
	@Override
	public void createPartControl(Composite parent) {
		// TODO create UI.
	}

	/** {@inheritDoc} */
	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
